/**
 * 
 */
package es.ats.codington.festival.junit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import junit.framework.TestCase;
import es.ats.codington.festival.domain.Visitor;
import es.ats.codington.festival.services.VisitorServiceImpl;

/**
 * The Class TVService.
 *
 * @author 5Cs
 */
public class TVService extends TestCase{

	/**
	 * Sets the up.
	 *
	 * @throws Exception the exception
	 */
	@Before
	public void setUp() throws Exception {
		super.setUp();
	}

	/**
	 * Tear down.
	 *
	 * @throws Exception the exception
	 */
	@After
	public void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link es.ats.codington.festival.services.VisitorServiceImpl#registerVisitor(es.ats.codington.festival.domain.Visitor)}.
	 */
	@Test
	public void testRegisterVisitor() {
		VisitorServiceImpl visitorService = new VisitorServiceImpl();
		Visitor visitor = new Visitor(8,"Francisco","Lanzas",28, "Rivera Street,1,1A","FranPC","123456","679585666",true);
		try {
			assertEquals(visitorService.registerVisitor(visitor), true);
		} catch (Exception ex) {
			fail("Exception should be thrown");
		}
	}
	
	/**
	 * Test method for {@link es.ats.codington.festival.services.VisitorServiceImpl#showVisitor(es.ats.codington.festival.domain.Visitor)}.
	 */
	@Test
	public void testShowVisitor() {
		VisitorServiceImpl visitorService = new VisitorServiceImpl();
		try {
			Visitor visitor = visitorService.searchVisitorByUsername("FranPC");
			assertEquals(visitor.getUsername(), "FranPC");
		} catch (Exception ex) {
			fail("Exception should be thrown");
		}
	}

	/**
	 * Test method for {@link es.ats.codington.festival.services.VisitorServiceImpl#updateVisitor(es.ats.codington.festival.domain.Visitor)}.
	 */
	@Test
	public void testUpdateVisitor() {
		VisitorServiceImpl visitorService = new VisitorServiceImpl();
		try {
			Visitor visitor = visitorService.searchVisitorByUsername("FranPC");
			visitor.setUsername("FranLC");
			assertEquals(visitorService.updateVisitor(visitor), true);
		} catch (Exception ex) {
			fail("Exception should be thrown");
		}
	}
	
	/**
	 * Test method for {@link es.ats.codington.festival.services.VisitorServiceImpl#searchVisitorById(int)}.
	 */
	@Test
	public void testSearchVisitorById() {
		VisitorServiceImpl visitorService = new VisitorServiceImpl();
		try {
			Visitor visitor = visitorService.searchVisitorByUsername("FranLC");
			assertNotNull(visitor.getName());
		} catch (Exception ex) {
			fail("Exception should be thrown");
		}
	}
	
	/**
	 * Test method for {@link es.ats.codington.festival.services.VisitorServiceImpl#deleteVisitor(int)}.
	 */
	@Test
	public void testDeleteVisitor() {
		VisitorServiceImpl visitorService = new VisitorServiceImpl();
		Visitor visitor = new Visitor();
		try {
			visitorService.registerVisitor(visitor);
			visitor = visitorService.searchVisitorByUsername("FranLC");
			assertEquals(visitorService.deleteVisitor(visitor.getVisitorId()), true);
		} catch (Exception ex) {
			fail("Exception should be thrown");
		}
	}


	/**
	 * Test method for {@link es.ats.codington.festival.services.VisitorServiceImpl#loginVisitor(es.ats.codington.festival.domain.Visitor)}.
	 *
	 * @param username the username
	 * @param password the password
	 */
	@Test
	public void testLoginVisitor(String username, String password) {
		VisitorServiceImpl visitorService = new VisitorServiceImpl();
		Visitor visitor = new Visitor();
		try {
			visitorService.registerVisitor(visitor);
			visitor = visitorService.searchVisitorByUsername("FranLC");
			assertEquals(visitor.getUsername(), username);
			assertEquals(visitor.getPassword(), password);
		} catch (Exception ex) {
			fail("Exception should be thrown");
		}
	}

}
